package cl.sodexo.com.delegate;

import org.apache.log4j.Logger;

import cl.psep.bean.EmailBean;
import cl.psep.mail.Email;
import cl.sodexo.com.utils.Constantes;

/**
 * @author psep
 *
 */
public abstract class MailDelegate {
	
	private final static Logger logger = Logger.getLogger(MailDelegate.class);
	private static String path = System.getProperty("jboss.server.home.dir") + Constantes.XMLMAIL;
	
	protected String toMail;
	protected String subject;
	protected String message;
	
	/**
	 * 
	 */
	protected void enviaEmail(){
		EmailBean emailBean = new EmailBean();
		emailBean.setToMail(this.toMail);
		emailBean.setSubject(this.subject);
		
		emailBean.setMessage(this.message);
		
		Email email = new Email(emailBean);
		
		try{
			email.loadFromXML(path);
			
			if(email.sendMail()){
				logger.info("OK");
			}else{
				logger.info("error");
			}
			
		}catch (Exception e) {
			logger.error(e, e);
		}
	}

}
